import 'dart:typed_data';
import 'package:flutter/material.dart';
import 'package:qrscan/qrscan.dart' as scanner;

class BarCode extends StatefulWidget {
  @override
  _BarCodeState createState() => _BarCodeState();
}

class _BarCodeState extends State<BarCode> {
  String barcode = '';
  Uint8List bytes = Uint8List(200);
  Future _scan() async {

    String barcode = await scanner.scan();
    setState(() {
      this.barcode = barcode;
    });
  }

  Future _scanPhoto() async {
    String barcode = await scanner.scanPhoto();
    setState(() {
      this.barcode = barcode;
    });
  }

  Future _generateBarCode() async {
    Uint8List result = await scanner.generateBarCode('https://github.com/leyan95/qrcode_scanner');
    setState(() {
      this.bytes = result;
    });
  }
  @override
  Widget build(BuildContext context) {
    return Container(
      child: Column(
        children: <Widget>[
          RaisedButton(
            child: Text('Scan'),
            onPressed: _scan,
          ), 
          RaisedButton(
            child: Text('scanPhoto'),
            onPressed: _scanPhoto,
          ), 
          RaisedButton(
            child: Text('generateBarCode'),
            onPressed: _generateBarCode,
          ), 
        ],
      ),
    );
  }
}